package com.kdweibo.demo.activities;

import java.io.File;
import java.util.List;

import kdweibo4j.Paging;
import kdweibo4j.Status;
import kdweibo4j.Weibo;
import kdweibo4j.WeiboException;
import kdweibo4j.http.AccessToken;


/**
 * 社区没有关注关系，使用publicTimeline 获取微博列表
 * @author winters_huang
 *
 */
public class TestStatusNew {
	String token = "";
	String tokenSecret = "";
	String network = "kdweibo.cn";
	String groupID = "4f705c1d24acec7da09e2b03";
	String msg = "from api demo test.";
	
	/**
	 * 发送公共微博
	 * 
	 */
	public void sendStatusMessage(){
		
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		
		try {
			Status status = weibo.updateStatus(msg);
			System.out.println("微博发送成功，返回内容："+status.id+", "+status.text);
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 发送小组微博
	 * 
	 */
	public void sendStatusMessage2Group(){
		
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		msg = msg+", to groupID:"+groupID;
		try {
			Status status = weibo.updateStatus(msg, groupID);
			System.out.println("微博发送成功，返回内容："+status.id+", GroupName:"+status.groupName+", Content"+status.text);
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 发送带图片的微博
	 * 
	 */
	public void sendStatusMessageWithImage(){
		
		Weibo weibo = AuthConstant.getInstance().getWeibo();
		weibo.setNetwork(network);
		weibo.setOAuthConsumer(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		weibo.setOAuthAccessToken(new AccessToken(token, tokenSecret));
		try {
			msg = "带图片的微博";
			Status status = weibo.uploadStatus(msg, new File("Mac OS X.jpg"));
			System.out.println("图片微博发送成功，返回内容："+status.id+", Content"+status.text);
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TestStatusNew dsn = new TestStatusNew();
		dsn.sendStatusMessage();
		dsn.sendStatusMessage2Group();
		dsn.sendStatusMessageWithImage();
	}
}
